********************************************************************************
** 	TITLE: b9_fcs_cleaning.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Community Survey Cleaning for Analysis
**	
**  INPUT: Raw Qualtrics Data for "FLINT Community Survey"
** 
**  OUTPUT: "$output_data/IGNITE_community_survey_clean.dta"	
********************************************************************************		
********************************************************************************
*A. Download Data
********************************************************************************
		set sortseed 13

	*Download as non-numeric (update with the date downloaded)
	capture import delimited using "$input_data/flint_community_survey/IGNITE+Flint+Community+Survey_December+18,+2023_06.57.csv", varnames(1) encoding(UTF-8) clear
	
	*Drop rows that aren't responses
	drop if strpos(startdate, "2023") == 0

/*
	Drop the people on tether wave; obs 89-102 who report being recruited at the 
	jail or while reporting on tether; note obs 99 reported receiving survey in 
	General Store, but for simplicity, we drop all of these observations as we know
	that they were recruited at the jail based on survey identifier.
 */
	gen obs = _n
	drop if obs > 88 & obs < 103
	//14 observations dropped. 106 obs remaining
	
	//Note on individuals who spent time in jail and had family/friends who spent time in jail
	list beeninjail friend_family_jail if beeninjail == "Yes" & strpos(friend_family_jail, "Yes") > 0 
	//16 of the 106 individuals noted in survey having self spent time in jail and know family/friend who spent time in jail. 
	
********************************************************************************
*B. Create Labels for Encoded variables
********************************************************************************	
	*clean variable names
	
	replace friend_family_bookin_1 = "Before 2000" if friend_family_bookin_1 == "Before 2003"
/*
	Mistake made in survey, was supposed to be "Before 2000" to be consistent with
	booked_to_jail_1 variable. Only one variable is changed, obs 106. If we redefined
	category for booked_to_jail_1 as  "Before 2003", no changes would be made. Thus,
	for simplicity, we use "Before 2000" category. 
 */

	replace q41 = "1-5 months" if q41 == "2-5 months"
	//Mistake made in survey. However no current observations were affected by the change. 

	*Creating Labels for variables
	label define beeninjail 0 "No" 1 "Yes"
	label define timesinjail 1 "1 to 3" 2 "4 to 6" 3 "7 or more"
	label define jail_year 2000 "Before 2000" 2001 "2001" 2002 "2002" 2003 "2003" 2004 "2004" 2005 "2005" 2006 "2006" ///
	2007 "2007" 2008 "2008" 2009 "2009" 2010 "2010" 2011 "2011" 2012 "2012" 2013 "2013" 2014 "2014" 2015 "2015" 2016 "2016" ///
	2017 "2017" 2018 "2018" 2019 "2019" 2020 "2020" 2021 "2021" 2022 "2022" 2023 "2023"
	//Given the responses, could redefine before 2000 as 2000 and before, so this definition suffices. 
	
	label define jail_month 1 "January" 2"February" 3 "March" 4 "April" 5 "May" ///
	6 "June" 7 "July" 8 "August" 9 "September" 10 "October" 11 "November" 12 "December"
	label define jail_length 1 "Less than 1 month" 2 "1-5 months" ///
	3 "6 months to a year" 4 "Greater than a year" 5 "They are still in jail"
	label define prob_parole 0 "No" 1 "Yes"
	label define name_jail 1 "Genesee County Jail" 2 "Saginaw County Jail" ///
	3 "Other Jail (Fill in text box below)"
	label define self_respect 1 "Strongly disagree" 2 "Somewhat disagree" ///
	3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"
	label define self_hopeful 1 "Less hopeful" 2 "Neutral" 3 "More hopeful" 
	label define self_most_hopeful1 1 "Education" 2 "Employment" 3 "Family" ///
	4 "Staying out of jail" 5 "Other "
	label define ff_better_worse 1 "Much worse" 2 "Somewhat worse" 3 "About the same" ///
	4 "Somewhat better" 5 "Much better"
	label define law_enforecement_op 1 "Strongly disagree" 2 "Somewhat disagree" ///.
	3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"
	label define male 0 "Female" 1 "Male"
	label define educ 1 "No high school degree" 2 "High school degree or GED" 3 "Some college" 4 "Completed college or more"
	label define age 1 "18-24 years" 2 "25-34 years" 3 "35-44 years" 4 "45-54 years" ///
	5 "55-64 years" 6 "65 years or older"
	label define recruited 1 "Barber Shop" 2 "Church" 3 "General store (e.g. Dollar Tree, Five Below)" ///
	4 "Other (Fill in text box below)" 5 "Social Security Office" 6 "Jail"
	
********************************************************************************
*C. Create Identifiers for Survey Branch (e.g. self in jail, friend or fam in jail)
********************************************************************************		
	
	encode booked_to_jail_1, gen(self_jail_year) label(jail_year)
	encode booked_to_jail_2, gen(self_jail_month) label(jail_month)
	
	*create binary for in jail 2016 or later personally
	gen self_jail_post_2016 = 0
	replace self_jail_post_2016 = 1 if beeninjail == "Yes" & self_jail_year >=2016
	//Note that our Genesee County Jail booking analysis sample begins in 2016 (with a 2015 leave-out sample)

	*create identifier for friend in jail
	gen friend_jail = .
	replace friend_jail = 0 if friend_family_jail != ""
	replace friend_jail = 1 if strpos(friend_family_jail, "Yes, a friend") > 0

	*create identifier for family member in jail
	gen fam_jail = . 
	replace fam_jail = 0 if friend_family_jail != ""
	replace fam_jail = 1 if strpos(friend_family_jail, "Yes, a family") > 0
	
	*create identifier for friend or fam in jail
	gen ff_jail = .
	replace ff_jail = 0 if friend_family_jail != ""
	replace ff_jail = 1 if friend_jail == 1 | fam_jail == 1
	lab define yes_no 0 "No" 1 "Yes"
	la values friend_jail yes_no
	la values fam_jail yes_no
	la values ff_jail yes_no
	
	*encode ff bookin month and year 
	encode friend_family_bookin_1, gen(ff_jail_year) label(jail_year)
	encode friend_family_bookin_2, gen(ff_jail_month) label(jail_month)	
	
	*Friend or fam in jail 2016 or later
	gen ff_jail_post_2016 = 0
	replace ff_jail_post_2016 = 1 if ff_jail == 1 & ff_jail_year >=2016
	//Note that our Genesee County Jail booking analysis sample begins in 2016 (with a 2015 leave-0ut sample)
	la values ff_jail_post_2016 yes_no
	la values self_jail_post_2016 yes_no
	
********************************************************************************
*D. Create Dummy Variables for Questions that Were Select Multiple
********************************************************************************		
	*Generate dummies for select multiple questions
		**Redefining the non-missing values based on non-missing responses instead of the post-2016 variable.

	*Self Current Activities
	forvalues i = 1(1)7 {
		gen self_activity`i' = .
		replace self_activity`i' = 0 if currently_doing != ""
		//Note that our Genesee County Jail booking analysis sample begins in 2016 (with a 2015 leave-0ut sample)
		cap la define activityl 0 "No" 1 "Yes"
		la values self_activity`i' activityl
	}
	
	*create binaries for each current activity
	replace self_activity1 = 1 if strpos(currently_doing, "Looking for work") > 0	
	replace self_activity2 = 1 if strpos(currently_doing, "Taking classes") > 0	
	replace self_activity3 = 1 if strpos(currently_doing, "Working for pay") > 0	
	replace self_activity4 = 1 if strpos(currently_doing, "Receiving government assistance") > 0	
	replace self_activity5 = 1 if strpos(currently_doing, "Taking care of children or elderly family members") > 0	
	replace self_activity6 = 1 if strpos(currently_doing, "Other") > 0	
	replace self_activity7 = 1 if strpos(currently_doing, "None of the above") > 0	
	
	*Self Program Participation
	forvalues i = 1(1)7 {
		gen self_program`i' = .
		replace self_program`i' = 0 if program_participate != ""
		cap la define programl 0 "No" 1 "Yes"
		la values self_program`i' programl
	}
	
	*create binaries for each program
	replace self_program1 = 1 if strpos(program_participate, "Education") > 0	
	replace self_program2 = 1 if strpos(program_participate, "Job training") > 0	
	replace self_program3 = 1 if strpos(program_participate, "Health") > 0	
	replace self_program4 = 1 if strpos(program_participate, "Well-being") > 0	
	replace self_program5 = 1 if strpos(program_participate, "IGNITE") > 0	
	replace self_program6 = 1 if strpos(program_participate, "Other") > 0	
	replace self_program7 = 1 if strpos(program_participate, "None of the above") > 0	

	codebook self_activity1-self_activity7 if self_jail_post_2016 != 1
	codebook self_program1-self_program7 if self_jail_post_2016 != 1
	
	
	*Friend or Family Activities
	forvalues i = 1(1)7 {
		gen ff_activity`i' = .
		replace ff_activity`i' = 0 if friend_currently_doi != ""
		cap la define activityl 0 "No" 1 "Yes"
		la values ff_activity`i' activityl
	}

	*create binaries for eac current activity friend fam
	replace ff_activity1 = 1 if strpos(friend_currently_doi, "Looking for work") > 0 
	replace ff_activity2 = 1 if strpos(friend_currently_doi, "Taking classes") > 0	
	replace ff_activity3 = 1 if strpos(friend_currently_doi, "Working for pay") > 0	
	replace ff_activity4 = 1 if strpos(friend_currently_doi, "Receiving government assistance") > 0	
	replace ff_activity5 = 1 if strpos(friend_currently_doi, "Taking care of children or elderly family members") > 0	
	replace ff_activity6 = 1 if strpos(friend_currently_doi, "Other") > 0	
	replace ff_activity7 = 1 if strpos(friend_currently_doi, "None of the above") > 0	
		
	*Friend or Family Program Participation
	forvalues i = 1(1)7 {
		gen ff_program`i' = .
		replace ff_program`i' = 0 if friend_family_partic != ""
		cap la define programl 0 "No" 1 "Yes"
		la values ff_program`i' programl
	}
	
	*create binaries for each current activity friend fam
	replace ff_program1 = 1 if strpos(friend_family_partic, "Education") > 0	
	replace ff_program2 = 1 if strpos(friend_family_partic, "Job training") > 0	
	replace ff_program3 = 1 if strpos(friend_family_partic, "Health") > 0	
	replace ff_program4 = 1 if strpos(friend_family_partic, "Well-being") > 0	
	replace ff_program5 = 1 if strpos(friend_family_partic, "IGNITE") > 0	
	replace ff_program6 = 1 if strpos(friend_family_partic, "Other") > 0	
	replace ff_program7 = 1 if strpos(friend_family_partic, "None of the above") > 0	
	

	codebook ff_activity1-ff_activity7 if ff_jail_post_2016 != 1
	codebook ff_program1-ff_program7 if ff_jail_post_2016 != 1
		
	
********************************************************************************
*D. Encode Varaibles
********************************************************************************	

	*Encode variables using labels defined in Code Section B
	encode recipientlastname, gen(ambassador)
	encode finished, gen(finished_survey)
	encode consent, gen(consented)
	replace consented = 0 if consented == 2
	//"Continue" denoted as 1 and "I do not consent to participate in this study" denoted as 2
	//three individuals of 106 observations chose not to consent. 
	
	destring duration, replace
	destring progress, replace
	destring locationlatitude, replace
	destring locationlongitude, replace
	
	encode beeninjail, gen(self_jail_experience) label(beeninjail)
	encode times_in_jail, gen(self_timesinjail) label(timesinjail)
	encode length_jail, gen(self_jail_length) label(jail_length)	
	encode jail_name, gen(self_name_jail) label(name_jail)
	encode probation_parole, gen(prob_parole) label(prob_parole)
	encode hopeful, gen(self_hopeful) label(self_hopeful)
	encode treated_respect, gen(self_respect) label(self_respect)	
	encode hopeful_about, gen(self_most_hopeful) label(self_most_hopeful)
	
	encode q41, gen(ff_jail_length) label(jail_length)		
	encode freind_family_releas, gen(ff_name_jail) label(name_jail)
	encode friend_family_worse, gen(ff_better_worse) label(ff_better_worse)
	encode friendfam_hopeful, gen(ff_hopeful) label(self_hopeful)
	encode v50, gen(ff_most_hopeful) label(self_most_hopeful)
	
	encode law_enforecement_op, gen(law_enforcement) label(law_enforecement_op)
	encode sex, gen(male) label(male)
	encode age, gen(age_grp) label(age)
	encode educ, gen(education) label(educ)
	encode recruited, gen(recruitment_site) label(recruited)
	
	*Race
	gen black = .
	replace black = 0 if race != ""
	replace black = 1 if strpos(race, "Black") > 0
	
	gen white = .
	replace white = 0 if race != ""
	replace white = 1 if strpos(race, "White") > 0
	
	gen hispanic = .
	replace hispanic = 0 if race != ""
	replace hispanic = 1 if strpos(race, "Hispanic") > 0
	
	gen other_race = .
	replace other_race = 0 if race != ""
	replace other_race = 1 if strpos(race, "Other") > 0
	
	la values black yes_no
	la values white yes_no
	la values hispanic yes_no
	la values other_race yes_no
	
********************************************************************************
*E. Rename, Order, and Keep Cleaned Variables
********************************************************************************	
	
	*Rename the free response variables
	rename jail_name_3_text self_otherjailname
	list self_otherjailname if self_otherjailname != ""
	//4 of 106 individuals listed other jails, including: Franklin County Jail |Livonia | Gladstone Police Department | West branch | Oakland county |

	rename program_participate_6_text self_otherprogramname 
	list self_otherprogramname if self_otherprogramname != ""
	//no one list other
	
	rename hopeful_about_5_text self_otherhopeful
	list self_otherhopeful if self_otherhopeful != ""
	//no one list other

	rename recruited_5_text recruitment_site_other
	tab recruitment_site_other if recruitment_site_other != ""
	list recruitment_site_other if recruitment_site_other != ""
	//40 out of 106 individuals listed other recruitment site, including:  Library  | Public Townhall at Library  |  Community Organization | Nation outside (Meeting) | [Surveyer name] | Flint public library  | Father Factor conference  | Father Hood event |  Community event | Family member  | Friend | Canvas  | Brennan Senior Center  |  Hospital  | Bar | Work/Employer | Laundromat |

	rename race_4_text other_race_text
	list other_race_text if other_race_text != ""
	//2 out of 106 individuals listed other race: Native Indian | Moorish American |

	rename friendfam_hopeful_5_text ff_otherhopeful
	list ff_otherhopeful if ff_otherhopeful != ""
	//2 out of 106 individuals listed other hopeful: Being successful | Getting out of jail |

	rename friend_family_partic_6_text ff_otherprogramname
	list ff_otherprogramname if ff_otherprogramname != ""
	//1 out of 106 individuals listed fam/friend other program: Drug program |
	
	rename freind_family_releas_3_text ff_otherjailname
	list ff_otherjailname if ff_otherjailname != ""
	//4 out of 106 individuals listed fam/friend other jail: Auburn Hills  | Lapeer | Oakland County  | Honestly I don’t know the name |

	 
	*Drop raw variables
	drop finished responseid recipientfirstname recipientlastname recipientemail ///
	externalreference distributionchannel userlanguage consent beeninjail  ///
	times_in_jail booked_to_jail_1 booked_to_jail_2 length_jail probation_parole ///
	jail_name program_participate treated_respect hopeful hopeful_about ///
	friend_family_bookin_1 friend_family_bookin_2 q41 freind_family_releas ///
	friend_family_worse friendfam_hopeful friend_family_partic currently_doing ///
	friend_currently_doi v50 law_enforecement_op race educ giftcard_url status ///
	recruited age sex friend_family_jail 
	
	*Reorder variables
	order startdate enddate recordeddate progress durationinseconds ipaddress ///
	locationlatitude locationlongitude ambassador recruitment_site recruitment_site_other male age_grp ///
	education black white hispanic other_race other_race_text self_jail_post_2016 ff_jail_post_2016 ///
	self_jail_experience self_timesinjail self_jail_year self_jail_month self_jail_length ///
	self_jail_post_2016 prob_parole self_name_jail self_otherjailname self_program1 ///
	self_program2 self_program3 self_program4 self_program5 self_program6 self_program7 self_otherprogramname ///
	self_respect experience_one_word self_hopeful self_activity1 self_activity2 ///
	self_activity3 self_activity4 self_activity5 self_activity6 self_activity7 ///
	self_most_hopeful self_otherhopeful fam_jail friend_jail ff_jail ff_jail_year ff_jail_month ///
	ff_jail_length ff_name_jail ff_otherjailname ff_program1 ff_program2 ff_program3 ff_program4 ///
	ff_program5 ff_program6 ff_program7 ff_otherprogramname ff_activity1 ff_activity2 ff_activity3 ///
	ff_activity4 ff_activity5 ff_activity6 ff_activity7 ff_better_worse ff_hopeful ///
	ff_most_hopeful ff_otherhopeful law_enforcement 
	
	format recordeddate %8s 
	
********************************************************************************
*G. Construct Variables
********************************************************************************		
	*Create date survey taken variable
	split recordeddate, gen(date)
	gen date = date(date1, "YMD")
	format date %td
	rename date2 time
	drop date1
	gen sdate = string(date, "%td")
	capture ssc install labutil
	labmask date, values(sdate) //used to output dates in figures/tables
	gen survey_month = mofd(date)
	format survey_month %tm
	
	*Create IGNITE Release date
	gen month_self_booked = ym(self_jail_year, self_jail_month) //Month booked
	gen month_ff_booked = ym(ff_jail_year, ff_jail_month) 
	format month_self_booked %tm
	format month_ff_booked %tm
	
	*Month Booked to Jail
	gen month_booked = month_self_booked
	replace month_booked = month_ff_booked if !missing(month_ff_booked)
	//Although individuals may have also been booked themselves, if asked about friend and family member more recent booking and one existed, all questions that follow on incarceration based on family/friend. 
	
	format month_booked %tm
	
	*Create a length variable converted to months
	gen length = 0 //Length of time in jail: <1 month recoded to 1 month, 1-5 months recoded to 3 months, 6 months - 1 year recoded to 9 months. Over 1 year recoded to 12 months.
	//note that IGNITE exposure will be based on discrete months relative to the IGNITE start month 
	replace length = 1 if self_jail_length == 1 | ff_jail_length == 1
	replace length = 3 if self_jail_length == 2 | ff_jail_length == 2
	replace length = 9 if self_jail_length == 3 | ff_jail_length == 3
	replace length = 12 if self_jail_length == 4 | ff_jail_length == 4
	replace length = . if ff_jail_length ==5
	
	*Create month released variable by adding months in jail to month booked to jail
	gen month_released = month_booked + length // month released is the month booked plus the time spent in jail (this is approx given jail time is categorical )
	format month_released %tm
	
	
	*Create a factor variable version of length in jail
	gen lengthfactor = self_jail_length
	replace lengthfactor = ff_jail_length if !missing(ff_jail_length)
	//Although individuals may have also been booked themselves, if asked about friend and family member more recent booking and one existed, all questions that follow on incarceration based on family/friend. 

	replace lengthfactor = 0 if ff_jail != 1 & self_jail_experience !=1
	//19 out of 106 individuals did say that either themselves or a family/loved one was in jail.
	replace lengthfactor = . if lengthfactor == 5	
	//7 out of 106 individuals whose family/friend still are in jail

	*Adjust the length variable for individuals who have a friend or family member still in jail
	gen length_jail_still = survey_month - month_booked if ff_jail_length == 5 // month surveyed minus month booked is equal to months in jail for those who are still in jail
	
	*Create a factor variable out of this
	//what about those whose jail_still is 1 or 0?
	list length_jail_still if length_jail_still == 0 | length_jail_still == 1
	//there are no cases of such so this is okay.
	gen still_jail_factor = 2 if length_jail_still > 1 & length_jail_still < 6
	replace still_jail_factor = 3 if length_jail_still > 5 & length_jail_still < 13
	replace still_jail_factor = 4 if length_jail_still > 12 & !missing(length_jail_still)
	//variable still_jail_factor mimics the jail_length categorical options 2 "1-5 months" 3 "6 months to a year" 4 "Greater than a year" as lenghtfactor is defined as. 
	
	*Create a second variable of the length in jail factor variable but for people still in jail, interpolate the months
	gen lengthfactor2 = lengthfactor 
	replace lengthfactor2 = still_jail_factor if lengthfactor == .	
	
	drop length_jail_still still_jail_factor
	
	*Construct a variable for Post-IGNITE based on release 
	gen post_ignite = 0
	replace post_ignite = 1 if month_released >= 728 & !missing(month_released) //IGNITE september 2020 (728)
	replace post_ignite = 1 if ff_jail_length == 5	// if they are still in jail, then they must be post 
	
	*Binary for genessee county jail
	gen gcj = 0 //includes everyone who wasn't in GCJ
	replace gcj = 1 if self_name_jail == 1 | ff_name_jail == 1 //those who spent time in GCJ
	
	*Binary for positive view of law enforcement
	//4 "Somewhat agree" 5 "Strongly agree"
	gen le_positive = 1 if law_enforcement == 4 | law_enforcement == 5
	replace le_positive  = 0 if le_positive ==  .  & !missing(law_enforcement)
	
	*Binary for being hopeful (combines personal and FF)
	//3 "More hopeful" 
	gen total_hopeful = 1 if ff_hopeful == 3 | self_hopeful == 3
	replace total_hopeful= 0 if total_hopeful == . & (!missing(ff_hopeful)  | !missing(self_hopeful))
	
	** Self Booked 2016 or later
	//Note that our Genesee County Jail booking analysis sample begins in 2016 (with a 2015 leave-0ut sample)	
	gen self_post_2016 = .
	replace self_post_2016 = 0 if self_jail_experience == 1
	replace self_post_2016 = 1 if self_jail_year >= 2016 & self_jail_year != .
	
	**FF Booked 2016 or later
	//Note that our Genesee County Jail booking analysis sample begins in 2016 (with a 2015 leave-0ut sample)
	gen ff_post_2016 = .
	replace ff_post_2016 = 0 if ff_jail == 1
	replace ff_post_2016 = 1 if ff_jail_year >= 2016 & ff_jail_year != .

	tab ambassador, gen(ca)
	tab recruitment_site, gen(site)
	tab education, gen(educ)
	tab age_grp, gen(age)
	
	*Binary for no personal or FF jail
	gen no_jail = 0
	replace no_jail = 1 if self_jail_experience == 0 & ff_jail == 0
	la define no_jail 0 "no" 1 "yes"
	la values no_jail no_jail
	la var no_jail "No Personal or FF Jail Experience"
	
	*Binary for more hopeful (personal)
	//3 "More hopeful" 
	gen self_hopeful_binary = .
	replace self_hopeful_binary = 0 if self_hopeful == 1 | self_hopeful == 2
	replace self_hopeful_binary = 1 if self_hopeful == 3
	
	*Binary for more hopeful (FF)
	//3 "More hopeful" 
	gen ff_hopeful_binary = .
	replace ff_hopeful_binary = 0 if ff_hopeful == 1 | ff_hopeful == 2
	replace ff_hopeful_binary = 1 if ff_hopeful == 3

	*Binary for doing better (FF)
	//4 "Somewhat better" 5 "Much better"
	gen ff_better = .
	replace ff_better = 0 if ff_better_worse == 1 | ff_better_worse == 2 | ff_better_worse == 3
	replace ff_better = 1 if ff_better_worse == 4 | ff_better_worse == 5
	la define better 0 "Not doing better" 1 "Doing better"
	la values ff_better better

	*Binary for treated respect (self)
	//4 "Somewhat agree" 5 "Strongly agree"
	gen self_respect_binary = .
	replace self_respect_binary = 0 if self_respect == 1 | self_respect == 2 | self_respect == 3 
	replace self_respect_binary = 1 if self_respect == 4 | self_respect == 5
	la define resp 0 "Not treated with respect" 1 "Treated with Respect"

	*Binary for most hopeful about education or work (FF and self)
	//most_hopeful 1 "Education" 2 "Employment"
	gen educ_work_hopeful = .
	replace educ_work_hopeful = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace educ_work_hopeful = 1 if ff_most_hopeful == 1 | ff_most_hopeful == 2 | self_most_hopeful == 1 | self_most_hopeful == 2
	
	egen working_for_pay = rowmax(self_activity3 ff_activity3)
	//activity3 "Working for pay"
	
	egen educationnow = rowmax(self_activity2 ff_activity2)
	//activity2 "Taking classes"
	
	egen lookingwork = rowmax(self_activity1 ff_activity1)
	//activity1 "Looking for work"
	
	*Completed survey
	gen complete = .
	replace complete = 0 if consent == 1
	//Note 103 individuals out of 106 consented to the survey
	
	replace complete = 1 if education != .
	//the last question on the survey. 101 of 106 individuals completed the education question.
	
	*Ignite Exposure variable 
	//IGNITE defined as having spent time (self or family/friend) in Genesee County Jail on or after September 2020. 
	gen ignite_expose = 0
	replace ignite_expose = 1 if gcj == 1 & post_ignite == 1
	//31 of 106 individuals were themselves or friend/family members exposed to IGNITE.
	summ ignite_expose if gcj == 1
	//of 52 individuals who themselves or friend/family members spent time in GCJ, 60% were IGNITE-exposed.
	
	*Label variable values
	la define ignite_expose 0 "Not exposed" 1 "Ignite exposed"
	la values ignite_expose ignite_expose
	la define le_pos 0 "Not positive" 1 "Positive"
	la values le_pos le_pos
	la define hopeful 0 "Not more hopeful" 1 "More hopeful"
	la values total_hopeful hopeful
	la values self_hopeful_binary hopeful
	la values ff_hopeful_binary hopeful
	la values self_respect_binary resp
	
	*Most hopeful about
	egen most_hopeful = rowmax(self_most_hopeful ff_most_hopeful)
	la values most_hopeful self_hopeful
	local outcomes educationnow le_pos total_hopeful most_hopeful ff_hopeful_binary self_hopeful_binary ff_better self_respect_binary

	*Combine ff and self
	*Dummies for program participation
	//program1 "Education"
	gen education_program = .
	replace education_program = 0 if self_program1 != . | ff_program1 != .
	replace education_program = 1 if self_program1 == 1 | ff_program1 == 1
	
	//program2 "Job training"
	gen jobtraining = .
	replace jobtraining = 0 if self_program2 != . | ff_program2 != .
	replace jobtraining = 1 if self_program2 == 1 | ff_program2 == 1
	
	//program3 "Health"
	gen health = .
	replace health = 0 if self_program3 != . | ff_program3 != .
	replace health = 1 if self_program3 == 1 | ff_program3 == 1
	
	//program4 "Well-being"
	gen wellbeing = .
	replace wellbeing = 0 if self_program4 != . | ff_program4 != .
	replace wellbeing = 1 if self_program4 ==1 | ff_program4 == 1
	
	//program5 "IGNITE"
	gen ignite = .
	replace ignite = 0 if self_program5 != . | ff_program5 != .
	replace ignite = 1 if self_program5 == 1 | ff_program5 == 1
	
	//program6 "Other"
	gen other_program = .
	replace other_program = 0 if self_program6 != . | ff_program6 != .
	replace other_program = 1 if self_program6 == 1 | ff_program6 == 1
	
	*Dummies for currently doing
	//activity1 "Looking for work"
	gen lookwork = .
	replace lookwork = 0 if self_activity1 != . | ff_activity1 != .
	replace lookwork = 1 if self_activity1 == 1 | ff_activity1 == 1
	
	//activity2 "Taking classes"
	gen takeclass = .
	replace takeclass = 0 if self_activity2  != . | ff_activity2  != .
	replace takeclass = 1 if self_activity2 == 1 | ff_activity2 == 1
	
	//activity3 "Working for pay"
	gen workpay = .
	replace workpay = 0 if self_activity3  != . | ff_activity3  != .
	replace workpay = 1 if self_activity3 == 1 | ff_activity3 == 1	
	
	//activity4 "Receiving government assistance"
	gen govassistance = .
	replace govassistance = 0 if self_activity4  != . | ff_activity4  != .
	replace govassistance = 1 if self_activity4 == 1 | ff_activity4 == 1		
	
	//activity5 "Taking care of children or elderly family members"
	gen takecare = .
	replace takecare = 0 if self_activity5  != . | ff_activity5  != .
	replace takecare = 1 if self_activity5 == 1 | ff_activity5 == 1		
	
	*Dummies for most hopeful
	//most_hopeful 1 "Education"
	gen most_hopeful_educ = .
	replace most_hopeful_educ = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace most_hopeful_educ = 1 if ff_most_hopeful == 1 | self_most_hopeful == 1
	
	//most_hopeful 2 "Employment"
	gen most_hopeful_empl = .
	replace most_hopeful_emp = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace most_hopeful_emp = 1 if ff_most_hopeful == 2 | self_most_hopeful == 2
	
	//most_hopeful 3 "Family" 
	gen most_hopeful_fam = .
	replace most_hopeful_fam = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace most_hopeful_fam = 1 if ff_most_hopeful == 3 | self_most_hopeful == 3
	
	//most_hopeful 4 "Staying out of jail"
	gen most_hopeful_stayout = .
	replace most_hopeful_stayout = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace most_hopeful_stayout = 1 if ff_most_hopeful ==4 | self_most_hopeful ==4
	
	//most_hopeful 5 "Other"
	gen most_hopeful_other = .
	replace most_hopeful_other = 0 if ff_most_hopeful != . | self_most_hopeful != .
	replace most_hopeful_other = 1 if ff_most_hopeful ==5 | self_most_hopeful ==5
	
	*Length of time in jail (combine self and ff)
	gen total_length = self_jail_length
	replace total_length = ff_jail_length if !missing(ff_jail_length)
	
	*
	gen one_month = .
	replace one_month = 0 if total_length == 1 
	replace one_month = 1 if total_length ==2 | total_length == 3 | total_length == 3
	la define one_month 0 "Less than a month" 1 "Over a month" 
	la values one_month one_month

	*Create median of age bucket variable
	gen agemed = .
	//age 1 "18-24 years"
	replace agemed = 21 if age_grp == 1
	//age 2 "25-34 years"
	replace agemed = 29.5 if age_grp == 2
	//age 3 "35-44 years"
	replace agemed = 39.5 if age_grp == 3
	//age 4 "45-54 years"
	replace agemed = 49.5 if age_grp == 4
	//age 5 "55-64 years" 
	replace agemed = 59.5 if age_grp == 5
	//age 6 "65 years or older"
	replace agemed = 69.5 if age_grp == 6 // cant do median for 65+ so
	
	
	*variable for relation to jail (self, ff, or none)
	gen relation_to_jail = .
	//Self exposure incarcerated
	replace relation_to_jail = 1 if self_jail_experience == 1
	//Friend/Family exposure incarcerated
	replace relation_to_jail = 2 if ff_jail == 1
	//No incarceration exposure
	replace relation_to_jail = 3 if self_jail_experience != 1 & ff_jail != 1 
	
		*Create 2 year bins for time booked to jail
	//Note that the order of creating values implies that survey respondent who mentions they or others have been incarcerated, the most recent year of either incarceration will be their label. 
	//Before these edits variable only exists for those who themselves or someone they know spent time in jail on or after 2016.
	***Changing the variable value 1 = Pre-2016; 
	**value 6 = No jail exposure; but for now lets not use
summ ff_jail_year self_jail_year if ff_jail_year <= 2013 | self_jail_year <= 2013
	gen yearbin = .
	*replace yearbin = 1 if ff_jail_year == 0 | self_jail_year == 0 
	//Pre-2016
	replace yearbin = 1 if ff_jail_year < 2016 | self_jail_year < 2016
	//2016 and 2017
	replace yearbin = 2 if ff_jail_year == 2016 | self_jail_year == 2016 | ff_jail_year == 2017 | self_jail_year == 2017 
	//2018 and 2019
	replace yearbin = 3 if ff_jail_year == 2018 | self_jail_year == 2018 | ff_jail_year == 2019 | self_jail_year == 2019 
	//2020 and 2021
	replace yearbin = 4 if ff_jail_year == 2020 | self_jail_year == 2020 | ff_jail_year == 2021 | self_jail_year == 2021 
	//2022 and 2023
	replace yearbin = 5 if ff_jail_year == 2022 | self_jail_year == 2022 | ff_jail_year == 2023 | self_jail_year == 2023
	//No jail exposure
	*replace yearbin = 6 if ff_jail_year == . & self_jail_year == .
	
	*Create variable good_thing, which is a binary for if ff or self is taking classes working for pay, taking care of family member, or looking for work
	egen good_thing = rowmax(takeclass workpay takecare lookwork)
	gen ffgood_thing = .
	replace ffgood_thing = good_thing if ff_jail != .
	gen selfgood_thing = .
	replace selfgood_thing = good_thing if self_jail_experience == 1 & ff_jail == .
	
	drop if education == . // these people didnt finish survey (Education is the last question)
	//5 observations did not complete the education question
	
********************************************************************************
*F. Label Variables
********************************************************************************	
	*Label Variables
	la var male "Male"
	la var age_grp "Age Group"
	la var education "What is your highest level of education completed?"
	la var recruitment_site "Where were you recruited for this survey?"
	la var black "Black"
	la var white "White"
	la var hispanic "Hispanic"
	la var other_race "Other Race"
	la var self_jail_experience "Have you ever been booked into jail?"
	la var self_activity1 "(Looking for Work) Are you currently doing any of the following?"
	la var self_activity2 "(Taking Classes) Are you currently doing any of the following?"
	la var self_activity3 "(Working for pay that does not involve crime) Are you currently doing any of the following?"
	la var self_activity4 "(Receiving government assistance e.g. food stamps/SNAP, disability/SSDI) Are you currently doing any of the following?"
	la var self_activity5 "(Taking care of children or elderly family members) Are you currently doing any of the following?"
	la var self_activity6 "(Other) Are you currently doing any of the following?"
	la var self_activity7 "(None of the above) Are you currently doing any of the following?"
	la var self_most_hopeful "Which of the following are you most hopeful about?"
	la var self_program1 "(Education) During your most recent incarceration, did you participate in any programs?"
	la var self_program2 "(Job training) During your most recent incarceration, did you participate in any programs?"
	la var self_program3 "(Health) During your most recent incarceration, did you participate in any programs?"
	la var self_program4 "(Well-being) During your most recent incarceration, did you participate in any programs?"
	la var self_program5 "(IGNITE) During your most recent incarceration, did you participate in any programs?"
	la var self_program6 "(Other) During your most recent incarceration, did you participate in any programs?"
	la var self_program7 "(None of the above) During your most recent incarceration, did you participate in any programs?"
	la var friend_jail "(Yes, a friend) Has a close friend or family member ever spent time in a local jail?"
	la var fam_jail "(Yes, a family member) Has a close friend or family member ever spent time in a local jail?"
	la var ff_jail "Friend or Family Member Spent Time in Jail"
	la var ff_jail_year "(Year) Friend or Family Last booked to jail"
	la var ff_jail_month "(Month) Friend or Family Last booked to jail"
	la var self_jail_post_2016 "Respondent in Jail 2016 or Later"
	la var ff_jail_post_2016 "Friend or Family Member in Jail 2016 or Later"
	la var self_otherjailname "Where was your most recent stay in local jail? SELECTED OTHER"
	la var self_otherprogramname "During your most recent incarceration, did you participate in any programs? SELECTED OTHER"
	la var self_otherhopeful "Which of the following are you most hopeful about? SELECTED OTHER"
	la var self_jail_year "Year Last Booked to Jail"
	la var self_jail_month "Month Last Booked to Jail"
	la var self_timesinjail "How many times have you spent time in a local jail?"
	la var self_jail_length "About how long did you stay in jail during your most recent incarceration?"
	la var ff_better_worse "Do you believe your friend or family member that was incarcerated is doing worse or better since their time served?"
	la var ff_hopeful "Is your friend or family member less or more hopeful about their future NOW compared to before they were incarcerated?"
	la var ff_most_hopeful "Which of the following do you believe your friend or family member to be most hopeful about?"
	la var experience_one_word "Type one word to describe your experience during your most recent incarceration in a local jail."
	la var prob_parole "Are you currently on parole, probation, or tether?"
	la var self_name_jail "Where was your most recent stay in local jail?"
	la var self_respect "To what extent do you disagree or agree with the following statement: During my most recent incarceration, I was treated with respect."
	la var self_hopeful "Are you more or less hopeful about your future NOW compared to before you were incarcerated?"
	la var ff_jail_length "About how long did your friend or family member stay in jail during their most recent incarceration?"
	la var ff_name_jail "Where was your friend or family member's most recent stay in local jail?"
	la var ff_activity1 "(Looking for Work) Is your friend or family member currently doing any of the following?"
	la var ff_activity2 "(Taking Classes) Is your friend or family member currently doing any of the following?"
	la var ff_activity3 "(Working for pay that does not involve crime) Is your friend or family member currently doing any of the following?"
	la var ff_activity4 "(Receiving government assistance e.g. food stamps/SNAP, disability/SSDI) Is your friend or family member currently doing any of the following?"
	la var ff_activity5 "(Taking care of children or elderly family members) Is your friend or family member currently doing any of the following?"
	la var ff_activity6 "(Other) Is your friend or family member currently doing any of the following?"
	la var ff_activity7 "(None of the above) Is your friend or family member currently doing any of the following?"	
	la var ff_program1 "(Education) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program2 "(Job training) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program3 "(Health) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program4 "(Well-being) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program5 "(IGNITE) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program6 "(Other) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var ff_program7 "(None of the above) During their most recent incarceration, did your friend or family member participate in any programs?"
	la var law_enforcement "To what extent do you disagree or agree with the following statement: Law enforcement looks out for me and my community."
	la var consented "Consented"
	la var other_race_text "Open Response Other Race"
	la var recruitment_site_other "Other Recruitment Site"
	la var ff_otherjailname "Open Response Other Friend or Family Jail Name"
	la var ff_otherprogramname "Open Response Other Friend or Family Program Participation Name"
	la var ff_otherhopeful "Open Response Other Friend or Family Hopeful About"
	la var consent "Consented"
	la var complete "Complete Conditional on Consent"
	la var self_hopeful_binary "Self More Hopeful"
	la var ff_hopeful_binary "Friend or Family More Hopeful"
	la var ca1 "Community Ambassador A"
	la var ca2 "Community Ambassador B"
	la var ca3 "Pastor A"
	la var ca4 "Pastor B"
	la var site1 "Barbershop"
	la var site2 "Church"
	la var site3 "General Store"
	la var site4 "Other"
	la var site5 "Social Security Office"
	la var age1 "18-24 years"
	la var age2 "25-34 years"
	la var age3 "35-44 years"
	la var age4 "45-54 years"
	la var age5 "55-64 years"
	la var age6 "65 years or older"
	la var educ1 "No high school degree"
	la var educ2 "Some college"
	la var educ3 "High school degree or GED"
	la var educ4 "Completed college or more"
	la var self_jail_experience "Personally Booked"
	la var ff_jail "Friend or Family Member Booked"
	la var self_post_2016 "\hspace{3mm} Self Post 2015"
	la var ff_post_2016 "\hspace{3mm} FF Post 2015"
	la var no_jail "No Personal or Friend/Family Jail"
	la var le_positive "Law Enforcement Positive"
	la var gcj "Genesee County Jail"
	la var post_ignite "Post Released Sep 2020 or Later"
	la var total_hopeful "More Hopeful"
	la var ff_better "FF Doing Better"
	la var self_hopeful_binary "Self More Hopeful"
	la var self_respect "Self Treated Respectfully"
	la var ff_hopeful_binary "FF More Hopeful"
	la var ff_better "Self Doing Better"
	la var self_respect_binary "Treated with Respect"
	la var educ_work_hopeful "Most hopeful about education or work"
	la var working_for_pay "Currently Working for pay"
	la var educationnow "Currently taking classes"
	la var lookingwork "Currently Looking for work"
	la var ignite_expose "Exposed to IGNITE"
	la var most_hopeful "What are you most hopeful about?"
	la var education_program "Jail Education Program"
	la var jobtraining "Job Training Program"
	la var health "Health Program"
	la var wellbeing "Well-being Program"
	la var ignite "IGNITE Program"
	la var other_program "Other Program"
	la var lookwork "Looking for Work"
	la var takeclass "Taking Classes"
	la var govassistance "Government Assistance"
	la var takeclass "Taking Classes"
	la var most_hopeful_educ "Most Hopeful Education"
	la var most_hopeful_empl "Most Hopeful Employment"
	la var most_hopeful_fam "Most Hopeful Family"
	la var most_hopeful_stayout "Most Hopeful Staying out of jail"
	la var most_hopeful_other "Most Hopeful Other"
	la var total_length "Length in Jail Approx Recoded (Months)"	
	la var one_month "More than One Month in Jail (Binary)"
	la var released_from_jail_1 "Self Released from Jail Year"
	la var released_from_jail_2 "Self Released from Jail Month"
	la var friend_fam_released_1 "FF Released from Jail Year"
	la var friend_fam_released_2 "FF Released from Jail Month"
	la var takecare "Take care of Family"
	la var workpay "Working for Pay"
	la var agemed "Median Age"
	
	
*** EXPORT DATA	
	save "$output_data/IGNITE_community_survey_clean.dta", replace	
